package org.insia.smartposse.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.insia.smartposse.config.DAOFactory;
import org.insia.smartposse.metier.Company;
import org.insia.smartposse.metier.Freelance;
import org.insia.smartposse.metier.User;
/**
 * Action for the first step of freelance's subscription. 
 * @author sok hout
 *
 */
public class ShowDashboardAction extends Action {
	protected final Logger log = Logger.getLogger(getClass());
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	throws Exception {
		
		log.info("Dans: ShowDashboardAction");
		
		User user = (User) request.getSession().getAttribute("user");
		
		Freelance freelance = DAOFactory.getFreelanceDAO().get(user.getId());
		if (freelance != null) {
			request.getSession().setAttribute("freelance", freelance);
		} else {
			Company company = DAOFactory.getCompanyDAO().get(user.getId());
			request.getSession().setAttribute("company", company);
		}
		
		return mapping.findForward("dashboard");
	}
}
